//
//  MBSpaceSetTimerCell.m
//  MiBaoTu
//
//  Created by admin on 16/9/26.
//  Copyright © 2016年 com.caesartech15. All rights reserved.
//

#import "MBSpaceSetTimerCell.h"

@interface MBSpaceSetTimerCell () {
    UIView                  *_bgView;
    UILabel                 *_nickNameLb;
    UIView                  *_lineView;
    UIButton                *_contentBt;
    BOOL                    _isSelect;
}

@end
@implementation MBSpaceSetTimerCell

- (void)awakeFromNib {
    // Initialization code
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self onCreateUI];
    }
    return self;
}

- (void)onCreateUI
{
    self.backgroundColor = [UIColor clearColor];
    self.backgroundView = nil;
    
    //背景
    _bgView = [[UIView alloc]initWithFrame:CGRectZero];
    _bgView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:_bgView];
    
    //标题
    _nickNameLb = [[UILabel alloc]initWithFrame:CGRectZero];
    _nickNameLb.backgroundColor = [UIColor clearColor];
    _nickNameLb.textAlignment = NSTextAlignmentLeft;
    _nickNameLb.textColor = UIColorFromHex(0x333333);
    _nickNameLb.font = [UIFont systemFontOfSize:13.f];
    [_bgView addSubview:_nickNameLb];
    
    _contentBt = [UIButton buttonWithType:UIButtonTypeCustom];
    _contentBt.backgroundColor = [UIColor clearColor];
    [_contentBt setImage:[UIImage imageNamed:@"weigouxuan_fb"] forState:UIControlStateNormal];
    [_contentBt setImage:[UIImage imageNamed:@"gouxuan_fb"] forState:UIControlStateSelected];
    [_contentBt addTarget:self action:@selector(onSelectItemAction:) forControlEvents:UIControlEventTouchUpInside];
    [_bgView addSubview:_contentBt];
    
    //线
    _lineView = [[UIView alloc]initWithFrame:CGRectZero];
    _lineView.backgroundColor = [UIColorFromHex(0x999999) colorWithAlphaComponent:.35];
    [_bgView addSubview:_lineView];
    
}

//勾选
- (void)onSelectItemAction:(UIButton *)bt
{
    if (_timerString && _delegate && [_delegate respondsToSelector:@selector(onSelectTimer:withView:)]) {
        [_delegate onSelectTimer:_timerString withView:self];
    }
}

- (void)setTimerString:(NSString *)timerString
{
    _timerString = timerString;
    [self setNeedsLayout];
}

- (void)layoutSelectAction:(BOOL)isSelect
{
    _isSelect = isSelect;
    [self setNeedsLayout];
}

- (void)setOrientation:(UIDeviceOrientation)orientation
{
    _orientation = orientation;
    [self setNeedsLayout];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    //value
    _nickNameLb.text = _timerString;
    _contentBt.selected = _isSelect;
    
    //frame
    _bgView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 100*PERCEN);
    
    _nickNameLb.frame = CGRectMake((ISIPAD?460*PERCEN*(_orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):25*PERCEN), (_bgView.height-20)/2., 100, 20);
    
    UIImage *img = [UIImage imageNamed:@"weigouxuan_fb"];
    _contentBt.frame = CGRectMake(_bgView.width-25*PERCEN-img.size.width-(ISIPAD?440*PERCEN*(_orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):0), (_bgView.height-img.size.height)/2., img.size.width, img.size.height);
    
    _lineView.frame = CGRectMake((ISIPAD?440*PERCEN*(_orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):0), _bgView.height-1, _bgView.width-(ISIPAD?880*PERCEN*(_orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):0), 1);
}

@end
